#pragma once
#include <iostream>
#include <pthread.h>
namespace mutex_module
{
    class mutex
    {
    public:
        mutex()
        {
            pthread_mutex_init(&_mutex,nullptr);
        }
        ~mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
        void lock()
        {
            pthread_mutex_lock(&_mutex);
        }
        void unlock()
        {
            pthread_mutex_unlock(&_mutex);
        }
        pthread_mutex_t& mutex_get()
        {
            return _mutex;
        }
    private:
        pthread_mutex_t _mutex;

    };
    class lock_guard
    {
    public:
        lock_guard(mutex& mutex1)
        :_mutex(mutex1)
        {
            _mutex.lock();
        }
        ~lock_guard()
        {
            _mutex.unlock();
        }
    private:
        //记得添加& mutex是一个结构体里面存的有些信息 浅拷贝没用
        mutex& _mutex;
    };



}


